﻿/*
	***Copyright 2012, Gabriel Valentoni Guelfi***
	
	
	This file is part of GWebDev Actionscript API.
	
	GWebDev Actionscript API is a free software; you can redistribute it
 	and/or modify it within the terms of General Public License GNU the way it was released by Free Software Foundation.
	
	This program is distributed with the hope that can be useful, but UNWARRANTED; without implicit warranties of adequation
	to any market or application in particular. See the General Public License GNU for more details.
	
	You shall has received a copy of the General Public License GNU along with this software within a file named "license.txt", 
	if you hasn´t, please, subscribe to Free Software Foundation Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110-1301, USA.
	Or contact the author trough the e-mail address listed below.

*/

////// GWebDev Actionscript API //////
//
// Version: 0.1
// Author: Gabriel Valentoni Guelfi
// E-mail: gabriel.valguelfi@gmail.com
//
//////

package gwdflash.display{
	import flash.display.MovieClip;
	import flash.events.*;
	
	public class GWDMenu extends MovieClip{
		
		private var _buttons:Array;

		public function GWDMenu(styles:Object, btIcons:Array) {
			_buttons = new Array();
			
			for(var i:int = 0; i < btIcons.length; i++) {
				var button:MovieClip = new MovieClip();
				button.y = (btIcons[i].height + styles.menuPadding) * i + styles.menuPadding;
				button.buttonMode = true;
				button.addChild(btIcons[i]);
				button.name = String(i);
				_buttons.push(button);
				addChild(button);
			}
		}
		
		public function btClickEffects(handler:Function, remove:Boolean = false, priority:int = 0):void {
			for(var i:int = 0; i < _buttons.length; i++) {
				if(remove){
					_buttons[i].removeEventListener(MouseEvent.CLICK, handler);
				}else {
					_buttons[i].addEventListener(MouseEvent.CLICK, handler, false, priority, true);
				}
			}
		}
		
		public function btRollOverEffects(handler:Function, remove:Boolean = false, priority:int = 0):void {
			for(var i:int = 0; i < _buttons.length; i++){
				if(remove){
					_buttons[i].removeEventListener(MouseEvent.MOUSE_OVER, handler);
				}else {
					_buttons[i].addEventListener(MouseEvent.MOUSE_OVER, handler, false, priority, true);
				}
			}
		}
		
		public function set buttons(btIcons:Array):void {
			for(var i:int = 0; i < _buttons.length; i++){
				_buttons[i].removeChildAt(0);
				_buttons[i].addChild(btIcons[i]);
			}
		}
		
		public function get buttons():Array {
			return _buttons;
		}
	}
}